home *** CD-ROM | disk | FTP | other *** search
/ PCMania 64 / PCMania CD64_1.iso / pcmania / virus64 / antitxap.c next >
C/C++ Source or Header  |  1998-01-01  |  10KB  |  321 lines

  1. /*----------------------------------------------*/
  2. /* ANTITXAP (c) 1997 Por Javier Guerrero Díaz 
  3. /* Rastrea el sistema en busca del virus TXAPELA.
  4. /*
  5. /* La sintaxis es: ANTITXAP <unidad>.
  6. /* El programa buscará el virus en los archivos EXE de la unidad especificada.
  7. /* Programado con Borland C++ 5.02
  8. /*----------------------------------------------*/
  9. /*      Javier Guerrero Díaz     */
  10. /*     email: jgd@redestb.es     */
  11. /*-------------------------------*/
  12.  
  13. #include <stdio.h>
  14. #include <dos.h>
  15. #include <dir.h>
  16. #include <conio.h>
  17. #include <bios.h>
  18. #include <stdlib.h>
  19. #include <direct.h>
  20. #include <string.h>
  21. #include <io.h>
  22.  
  23. void fin(void);
  24. void mal(void);
  25. void intro(void);
  26. void buscafichero(void);
  27. void panta(void);
  28. void mensaje(char *mensa);
  29. void obtieneinfo(void);
  30. void atributo(char);
  31. void analiza(void);
  32. void encontrado(void);
  33. void matavir(void);
  34.  
  35. union REGS registros;
  36. char tecla,diractual[50],dirdestino[50];
  37. int temp,infec=0,analiz=0,pulsa;
  38. unsigned long memlibre=0;
  39. FILE *fichero;
  40. struct ffblk arch;
  41. struct date fecha;
  42. struct dostime_t hora;
  43.  
  44. unsigned int far *word;
  45. unsigned long salto;
  46. char cabexe[0x1C],clave[1];
  47.  
  48. void main(argc,argv)
  49. int argc;
  50. char *argv[];
  51. {
  52. if (*argv[1]==NULL || *argv[1]=='?') 
  53.         { printf("\nANTITXAP (c)1997 Por Javier Guerrero Díaz\n");
  54.               printf("Sintaxis: ANTITXAP <directorio>\n"); exit(-1);}
  55.  
  56. getcwd(diractual,50);
  57. _setcursortype(_NOCURSOR);
  58.  
  59. if (chdir(argv[1])==-1) { printf("\nError. No puedo acceder al directorio ");
  60.             printf("%s.\n",argv[1]); mal(); }
  61. getcwd(dirdestino,50);
  62. intro();
  63. panta();
  64. buscafichero();
  65. fin();
  66. }
  67.  
  68. void matavir(void)
  69. {
  70. unsigned long start,tamanoreal=0;
  71. int res=0,temp,handle,parcial=0;
  72. int far *totalpags,*numbytes;
  73.  
  74. totalpags=(int far*)MK_FP(FP_SEG(&cabexe[4]),FP_OFF(&cabexe[4]));
  75. numbytes=(int far*)MK_FP(FP_SEG(&cabexe[2]),FP_OFF(&cabexe[2]));
  76. if (*numbytes==0) tamanoreal=(*totalpags)*512;
  77. else if (*numbytes>0) 
  78.     { 
  79.      tamanoreal=(*totalpags)-1;
  80.      parcial=*numbytes;
  81.      tamanoreal*=512;
  82.      tamanoreal+=parcial;
  83.     } 
  84. rewind(fichero); 
  85. res=fwrite(cabexe,1,0x1C,fichero);
  86.     if (res!=0x1C) {
  87.              mensaje("Error escribiendo en archivo!."); goto sale;
  88.                }
  89. handle=fileno(fichero); res=chsize(handle,tamanoreal);
  90. if (res!=0) { 
  91.          mensaje("Error al modificar el tamaño del archivo."); goto sale;
  92.         }
  93. mensaje("OK!. Virus eliminado del fichero.");
  94. sale:
  95. }
  96.  
  97. void analiza(void)
  98. {
  99. char virus[]={ 0xBA,0xEB,0x09,0xB8,0x05,0xFE,0xEB,0xFC,0x80,
  100.         0xC4,0x3B,0xEB,0xF4,0xBB,0x1A,0x00 };
  101. char cadena[16];
  102. int res=0;
  103. unsigned int exe;
  104. unsigned long iniciovir=0,csini=0,tamcab=0,tempo=0;
  105.  
  106. exe=getw(fichero);
  107. if (exe==0x5A4D) 
  108.     { 
  109. res=fseek(fichero,8,SEEK_SET);
  110.     if (res!=0) { 
  111.              mensaje("Error gestionando fichero!."); mal();
  112.             }
  113. tamcab=getw(fichero); 
  114. tamcab*=16;
  115. res=fseek(fichero,0x16,SEEK_SET);
  116.     if (res!=0) { 
  117.              mensaje("Error gestionando fichero!."); mal();
  118.             }
  119. csini=getw(fichero); 
  120. csini*=16;
  121. iniciovir=tamcab+csini;
  122. res=fseek(fichero,iniciovir,SEEK_SET);
  123.     if (res!=0) { 
  124.              mensaje("Error gestionando fichero!."); mal();
  125.             }
  126. res=fread(cadena,1,16,fichero);
  127.     if (res!=16) { 
  128.               mensaje("Error leyendo archivo!.");
  129.              }
  130. if (strcmp(virus,cadena)==0) 
  131.     { 
  132.     tempo=iniciovir; iniciovir+=0x39;
  133.     res=fseek(fichero,iniciovir,SEEK_SET);
  134.         if (res!=0) { 
  135.                  mensaje("Error gestionando fichero!."); mal();
  136.                 }
  137.     res=fread(clave,1,1,fichero);
  138.         if (res!=1) { 
  139.                  mensaje("Error leyendo archivo!.");
  140.                 }
  141.     clave[0]^=0x90;
  142.     tempo+=0x5A2; iniciovir=tempo;
  143.     res=fseek(fichero,iniciovir,SEEK_SET);
  144.         if (res!=0) { 
  145.                  mensaje("Error gestionando fichero!."); mal();
  146.                 }
  147.     res=fread(cabexe,1,0x1C,fichero);
  148.         if (res!=0x1C) { 
  149.                 mensaje("Error leyendo archivo!.");
  150.                    }
  151.     for (res=0;res<0x1C;res++)
  152.         {
  153.          cabexe[res]^=clave[0];
  154.         }
  155.     encontrado();
  156.     textattr(LIGHTGRAY|BLACK<<4); clrscr(); panta(); obtieneinfo();
  157.     }
  158.     }
  159. sale:
  160. }
  161.  
  162. void encontrado(void)
  163. {
  164. window(22,8,57,20); infec++;
  165. textattr(WHITE|RED<<4);
  166. cprintf("╔═══════════╦══════════╦═══════════╗");
  167. cprintf("║           ║ ATENCION ║           ║");
  168. cprintf("║           ╚══════════╝           ║");
  169. cprintf("║                                  ║");
  170. cprintf("║                                  ║");
  171. cprintf("║                                  ║");
  172. cprintf("║                                  ║");
  173. cprintf("║                                  ║");
  174. cprintf("║ PULSE LA TECLA 'SUPR' PARA MATAR ║");
  175. cprintf("║  EL VIRUS O CUALQUIER OTRA PARA  ║");
  176. cprintf("║      IGNORAR ESTE FICHERO.       ║");
  177. cprintf("╚══════════════════════════════════╝");
  178. gotoxy(3,5); cprintf("SE DETECTO LA MARCA DE INFECCION");
  179. gotoxy(3,6); cprintf("   PROPIA DEL VIRUS 'TXAPELA' ");
  180. gotoxy(3,7); cprintf("    EN ARCHIVO:");
  181.  
  182. textattr(YELLOW|RED<<4); gotoxy(19,7); cprintf("%-12s",arch.ff_name);
  183. textattr(WHITE|BLUE<<4); window(1,1,80,25);
  184. mensaje("Atención: Fichero infectado por el virus !."); 
  185. tecla:    pulsa=bioskey(0);
  186.         switch (pulsa)
  187.         {
  188.             case 0x5300:    matavir();
  189.                     break;
  190.             case 0x532E:    matavir();
  191.                     break;
  192.             default:        break;
  193.         }
  194. }
  195.  
  196. void obtieneinfo(void)
  197. {
  198. getdate(&fecha);
  199. _dos_gettime(&hora);
  200. registros.h.ah=0x48; registros.x.bx=0xFFFF;
  201. int86(0x21,®istros,®istros);
  202. memlibre=registros.x.bx; memlibre*=16;
  203. gotoxy(14,11); cprintf("%02d/%02d/%d",fecha.da_day,fecha.da_mon,fecha.da_year);
  204. gotoxy(34,11); cprintf("%02d:%02d:%02d",hora.hour,hora.minute,hora.second);
  205. gotoxy(62,11); cprintf("%ld",memlibre); gotoxy(32,13); cprintf("%s",dirdestino);
  206. }
  207.  
  208. void buscafichero(void)
  209. {
  210. char far *atr,prot='N';
  211.  
  212. temp=findfirst("*.*",&arch,0);
  213.     while (!temp)
  214.         { atr=(char far *)&arch.ff_attrib;
  215.           if ((*atr & 1)) { prot='Y'; atributo((*atr ^ 1)); }
  216.           obtieneinfo();
  217.     fichero=fopen(arch.ff_name,"r+b");
  218.         if (fichero==NULL) 
  219.         { gotoxy(24,23);
  220.           cprintf("                                                  ");
  221.           gotoxy(24,23); cprintf("Error abriendo fichero!"); putch(7);
  222.           sleep(1); gotoxy(24,23);
  223.           cprintf("                                                  ");                        
  224.         }
  225.         analiz++;
  226.         if (arch.ff_fsize>0x633) analiza(); 
  227.         gotoxy(28,15);
  228.         cprintf("%-12s",arch.ff_name);
  229.         gotoxy(62,15);
  230.         cprintf("%-8ld",arch.ff_fsize);
  231.         gotoxy(33,17);
  232.         cprintf("%-3d",analiz); 
  233.         gotoxy(64,17);
  234.         cprintf("%-3d",infec);
  235.         fclose(fichero);
  236.         if (prot=='Y') { atr=(char far *)&arch.ff_attrib;
  237.                  atributo((*atr | 1)); prot='N'; }
  238.         temp=findnext(&arch);
  239.         }
  240.  
  241. chdir(diractual);       
  242. }
  243.  
  244. void intro(void)
  245. {
  246. clrscr(); gotoxy(20,9); textattr(YELLOW|BLUE<<4);
  247. cprintf("╔═════════════════════════════════════╗\n"); gotoxy(20,10);
  248. cprintf("║               ANTITXAP              ║\n"); gotoxy(20,11);
  249. cprintf("║ (c) 1997  Por Javier Guerrero Diaz. ║\n"); gotoxy(20,12);
  250. cprintf("║ Rastrea los archivos del directorio ║\n"); gotoxy(20,13);
  251. cprintf("║  especificado como parámetro a la   ║\n"); gotoxy(20,14);
  252. cprintf("║     busqueda del virus TXAPELA.     ║\n"); gotoxy(20,15);
  253. cprintf("╚═════════════════════════════════════╝\n");
  254. textattr(LIGHTGRAY|BLACK<<4);tecla=getch();
  255. clrscr();
  256. }
  257.  
  258. void panta(void)
  259. {
  260. window(20,2,60,7);
  261. gotoxy(1,1);
  262. textattr(YELLOW|BLUE<<4);
  263. cprintf("╔═══════════════════════════════════════╗");
  264. cprintf("║   DETECTOR/VACUNA DEL VIRUS TXAPELA   ║");
  265. cprintf("║     (C) Por Javier Guerrero Diaz      ║");
  266. cprintf("╚═══════════════════════════════════════╝");
  267. window(5,8,75,20);
  268. cprintf("╔═════════════════════════════════════════════════════════════════════╗");
  269. cprintf("║                         ANALISIS DE ARCHIVOS                        ║");
  270. cprintf("║                                                                     ║");
  271. cprintf("║ Fecha:               Hora:              Memoria Libre:        bytes ║");
  272. cprintf("║                                                                     ║");
  273. cprintf("║  Directorio de Búsqueda:                                            ║");
  274. cprintf("║                                                                     ║");
  275. cprintf("║  Nombre de Archivo :                 Longitud Archivo:              ║");
  276. cprintf("║                                                                     ║");
  277. cprintf("║      Archivos Analizados:           Archivos Infectados:            ║");
  278. cprintf("║                                                                     ║");
  279. cprintf("╚═════════════════════════════════════════════════════════════════════╝");
  280. window(1,22,80,25);
  281. cprintf("╔══════════════════════════════════════════════════════════════════════════════╗");
  282. cprintf("║ RESULTADO OPERACION:                                                         ║");
  283. cprintf("╚══════════════════════════════════════════════════════════════════════════════╝");
  284. textattr(WHITE|BLUE<<4); window(1,1,80,25);
  285. }
  286.  
  287. void fin(void)
  288. {
  289. _setcursortype(_NORMALCURSOR); textattr(LIGHTGRAY|BLACK<<4);
  290. exit(0);
  291. }
  292.  
  293. void mal(void)
  294. {
  295. _setcursortype(_NORMALCURSOR); textattr(LIGHTGRAY|BLACK<<4);
  296. printf("\nPrograma finalizado anormalmente.\n");
  297. exit(-1);
  298. }
  299.  
  300. void mensaje(mensa)
  301. char mensa[50];
  302. {
  303. window(1,1,80,25); textattr(WHITE|BLUE<<4); gotoxy(24,23);
  304. cprintf("                                                      ");
  305. gotoxy(24,23); cprintf("%s",mensa); putch(7);
  306. sleep(1); gotoxy(24,23);
  307. cprintf("                                                      ");                 
  308. }
  309.  
  310. void atributo(attrib)
  311. char attrib;
  312. {
  313. int nombre;
  314.  
  315. registros.x.ax=0x4301; registros.x.cx=attrib;
  316. nombre=FP_OFF(&arch.ff_name); registros.x.dx=nombre;
  317. int86(0x21,®istros,®istros);
  318. if (registros.x.cflag!=0) {
  319. mensaje("Error: No se pudo cambiar atributo de fichero."); mal(); }
  320. }
  321.